import axios from 'axios'
import * as types from './mutation-types.js'
export default {
	getUserProfile({commit}){
		return new Promise((resolve,reject)=>{
			axios.get('./user/profile')
					  .then((res)=> {
					     if(res.data.error == 0){
					     	commit(types.SET_USER_ID, res.data.data.user_id)
	                		commit(types.SET_USER_NAME, res.data.data.nickname);
	                		commit(types.SET_AVATAR, res.data.data.avatar)
					     }else{
					     	layer.msg(res.data.msg, {icon: 5});
					     }
					     resolve(res);
					  })
					  .catch((error)=>{
					  	 layer.msg(error, {icon: 5});
					  	 reject(error)
				      });
		})

	},
	isBanner({commit}){
		return new Promise((resolve,reject)=>{
				if(window.location.host.indexOf('1234tv') !== -1 && top.location === self.location){
					commit(types.SET_BANNER, 1);
					resolve();
				}else{
					axios.get('./banner')
				  .then((res)=> {
				    if(res.data.error === 0){
				     	commit(types.SET_BANNER, res.data.data.banner)
				    }else{
				     	layer.msg(res.data.msg, {icon: 5});
				    }
				    resolve(res);
				  })
				  .catch((error)=>{
			  		layer.msg(error, {icon: 5});
					 	reject(error)
			    });
				}
		})
	}
}